<?php 
require_once Path::interfaces('controller');
require_once Path::abstracts('controller');
require_once Path::models('dummy');
require_once Path::managers('dummy');


class DummyController extends ControllerAbstract implements ControllerInterface
{
	public function home()
	{
		$dummy = new DummyManager();
		$dummyList = $dummy->findAllManager($dummy);
		
		HTML::instance("dummy",$dummy);
		HTML::instance("dummyList",$dummyList);
		
		Render::view("dummy/home");
	}
	
	public function edit()
	{
		$instance = new DummyManager();
		
		$instance->set("dummyId",HTML::get("id","GET"));
		$instance = $instance->findManager($instance);
		
		HTML::instance("instance",$instance);
		
		Render::view("dummy/home");
	}
	
	public function save()
	{
		$instance = new DummyManager();
		$instance->set("dummyName", "sss");
		$instance->set("dummyUserId", 1);
		
		
		$instance->saveManager($instance);
		
	}

	public function insert()
	{
		$instance = new DummyManager();

		$instance->set("dummyName","TEST");

		// ตั้งค่าข้อมูลต่างๆ ที่นี่
		//	$instance->set("sampleData","01");

		$instance->saveManager($instance);
	}

	public function delete()
	{
		$instance = new DummyManager();

		// ตั้งค่าข้อมูลต่างๆ ที่นี่
		//	$instance->set("samplePrimary","01");

		$instance->deleteManager($instance);
	}

	public function view()
	{
		$instance = new DummyManager();

		// ตั้งค่าข้อมูลต่างๆ ที่นี่
		//	$instance->set("samplePrimary","01");

		echo $instance->findManager($instance);
	}

	public function find()
	{
		Console::write("Enter ".get_class($this)." -> ".__FUNCTION__);

		$instance = new DummyManager();
		$instance->set("dummyId",1);
		$instance = $instance->findManager($instance);

		if($instance!=NULL)
		{
			echo $instance->get("dummyName");
		}
		else
		{
			echo "not found";
		}

		Console::write("Exit ".get_class($this)." -> ".__FUNCTION__);
	}

	public function findAll()
	{
		Console::write("Enter ".get_class($this)." -> ".__FUNCTION__);

		$instance = new DummyManager();
		$instanceList = $instance->findAllManager($instance);

		if($instanceList==NULL)
		{
			echo "not found";
		}
		else
		{
			foreach ($instanceList as $instance)
			{
				echo $instance->get("dummyName")."<br/>";//parent::view("Default");
			}
		}

		Console::write("Exit ".get_class($this)." -> ".__FUNCTION__);
	}

	public function findNative()
	{
		Console::write("Enter ".get_class($this)." -> ".__FUNCTION__);
		$instance = new DummyManager();

		$instance = $instance->findNativeManager();

		if($instance!=NULL)
		{
			echo $instance['Dummy']->get("dummyName");//parent::view("Default");
		}
		else
		{
			echo "not found";
		}

	}

	public function findAllNative()
	{
		Console::write("Enter ".get_class($this)." -> ".__FUNCTION__);

		$instance = new DummyManager();
		$instanceList = $instance->findAllNativeManager();
		
// 		var_dump($instanceList);
// 		exit();

		if($instanceList==NULL)
		{
			echo "not found";
		}
		else
		{
			foreach ($instanceList as $instance)
			{
// 				var_dump($instance['Dummy']);
				echo $instance['Dummy']->get("dummyName")." - ";//parent::view("Default");
				echo $instance['DummyUser']->get("dummyUserName")."<br/>";
			}
		}

		Console::write("Exit ".get_class($this)." -> ".__FUNCTION__);
	}

	public function findCountNative()
	{
		Console::write("Enter ".get_class($this)." -> ".__FUNCTION__);

		$instance = new DummyManager();
		$instance = $instance->findCountNativeManager();
		echo $instance['Custom']->get("count");

		Console::write("Exit ".get_class($this)." -> ".__FUNCTION__);
	}

	public function sendInstance()
	{
		Console::write("Enter ".get_class($this)." -> ".__FUNCTION__);

		HTML::instance("test","bbb");

		Render::view("domain/home");

		Console::write("Exit ".get_class($this)." -> ".__FUNCTION__);
	}

	public function testXML()
	{
		$instance = new DummyController();
		$instance->set("dummyId", 1);
		parent::findXMLManager($instance);
	}

}
